#include <bits/stdc++.h>

using namespace std;
int t;
int n;
int a[220000];

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> t;
    for (int k = 1; k <= t; k++) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int res = -1;
        for (long long s = 0; s < (1 << n); s++) {
            int ans = 0;
            for (int j = n - 1; j >= 0; j--) {
                if ((1 << j) & s) {
                    for (int r = j + 1; r <= n - 1; r++) {
                        if ((1 << r) & s) {
                            if (a[n - r] == a[n - j]) {
                                ans += a[n - r];
                                break;
                            } else {
                                break;
                            }
                        }
                    }
                } else {
                    for (int r = j + 1; r <= n - 1; r++) {
                        if (!((1 << r) & s)) {
                            if (a[n - r] == a[n - j]) {
                                ans += a[n - r];
                                break;
                            } else {
                                break;
                            }
                        }
                    }
                }
            }
            res = max(res, ans);
        }
        cout << res << endl;
    }
    return 0;
}

